// »ÝÌ OpenGL ReLXgàÌ 'theView' ©ç 'texName' eNX`ð¶¬
-(void)textureFromView:(NSView*)theView textureName:(GLuint*)texName
{
// \[Xr
[©çrbg}bvð¶¬
NSBitmapImageRep * bitmap = [NSBitmapImageRep alloc];
int samplesPerPixel = 0;
[theView lockFocus];
[bitmap initWithFocusedViewRect:[theView bounds]];
[theView unlockFocus];
// ÇÝæérbg}bvÌKØÈsÌ·³ðÝè
glPixelStorei(GL_UNPACK_ROW_LENGTH, [bitmap pixelsWide]);
// ÇÝæézñÌoCgðÝè (rbg}bvÌsNZ ½è 3 oCgKv)
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
// eNX`ªn³êÈ¢êÍAVµ¢eNX`IuWFNgð¶¬
if (*texName == 0)
glGenTextures (1, texName);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, *texName);
// ~bv}bvȵÌtB^ (texture_rectangle ÉÍç·)
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,
GL_TEXTURE_MIN_FILTER, GL_LINEAR);
samplesPerPixel = [bitmap samplesPerPixel];
// ñ PlanerARGB 24 rbgrbg}bvAÜ½Í RGBA 32 rbgrbg}bv
if(![bitmap isPlanar] &&
(samplesPerPixel == 3 || samplesPerPixel == 4)) {
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT,
0,
samplesPerPixel == 4 ? GL_RGBA8 : GL_RGB8,
[bitmap pixelsWide],
[bitmap pixelsHigh],
0,
samplesPerPixel == 4 ? GL_RGBA : GL_RGB,
GL_UNSIGNED_BYTE,
[bitmap bitmapData]);
} else {
/*
G[óÔ...
ãÌR[hÅÍ 2 ÂÌP[X (24 rbg RGBA¨æÑ 32 rbg RGBA) ª³êĨèA
KvÅ êÎAÙ©Ìrbg}bv`®ÌT|[gàÂ\B
¢Â©ÌLpÈîñðOÉ«o·B
*/
NSLog (@"-textureFromView: Unsupported bitmap data
format: isPlanar:%d, samplesPerPixel:%d, bitsPerPixel:%d,
bytesPerRow:%d, bytesPerPlane:%d",
[bitmap isPlanar],
[bitmap samplesPerPixel],
[bitmap bitsPerPixel],
[bitmap bytesPerRow],
[bitmap bytesPerPlane]);
}
// N[Abv
[bitmap release];
}
|